// pages/mirrordetails/mirrordetails.js
var app = getApp();
var com = require('../../common.js');
var wxParse = require('../../wxParse/wxParse.js')
Page({
  data: {
    id: '',
    sale: '',
    statusd: 1
  },
  onLoad: function (options) {
    var _this = this
    _this.setData({
      id: options.id
    })
    _this.couponse()
    setTimeout(() => {
      _this.setData({
        statusd: 0
      })
    }, 1500)
  },
  onReady: function () { },
  onShow: function () { },
  onHide: function () { },
  onUnload: function () { },
  onPullDownRefresh: function () { },
  onReachBottom: function () { },
  // onShareAppMessage: function() {},
  couponse() {
    var _this = this
    com.link(app.link.couponsCentent + _this.data.id + '.st', {}, function (res) {
      console.log(res)
      _this.setData({
        info: res.data.data,
      })
      wxParse.wxParse('content', 'html', res.data.data.postscript, _this, 10)
    }, 'GET')
  },
  //镜券上下架
  coupon_sale() {
    var _this = this
    if (_this.data.sale == '') {
      wx.navigateBack({
        delta: 1
      })
    } else {
      var l = []
      l.push(_this.data.id)
      com.link(app.link.coupon_sale, {
        sale: _this.data.sale,
        items: l
      }, function (res) {
        console.log(res)
        if (res.data.state) {
          wx.showToast({
            title: '保存成功'
          })
          setTimeout(() => {
            wx.navigateBack({
              delta: 1
            })
          }, 1500)
        }
      })
    }
  },
  selected(e) {
    console.log(e)
    var _this = this
    _this.setData({
      sale: e.detail.value
    })
  }
})